home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / csfd.cz.ifs < prev    next >
Encoding:
Text File  |  2004-10-25  |  7.4 KB  |  255 lines

  1. // GETINFO SCRIPTING
  2. // Imports from csfd.cz
  3.  
  4. (***************************************************
  5.  *  by Dmitry501                                   *
  6.  *                                                 *
  7.  *  For use with Ant Movie Catalog 3.4.0           *
  8.  *  www.antp.be/software/moviecatalog              *
  9.  *                                                 *
  10.  *  This program is free software; you can         *
  11.  *  redistribute it and/or modify it under the     *
  12.  *  terms of the GNU General Public License as     *
  13.  *  published by the Free Software Foundation;     *
  14.  *  either version 2 of the License, or (at your   *
  15.  *  option) any later version.                     *
  16.  ***************************************************)
  17.  
  18. program Csfd_cz;
  19. const
  20.   BaseAddress = 'http://www.csfd.cz/';
  21. var
  22.   MovieName: string;
  23.  
  24. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  25. var
  26.   i: Integer;
  27. begin
  28.   result := -1;
  29.   if StartAt < 0 then
  30.     StartAt := 0;
  31.   for i := StartAt to List.Count-1 do
  32.     if Pos(Pattern, List.GetString(i)) <> 0 then
  33.     begin
  34.       result := i;
  35.       Break;
  36.     end;
  37. end;
  38.  
  39. function GetDirector(Line: string): String;
  40. var BeginPos : Integer;
  41. begin
  42.     result := '';
  43.     BeginPos := Pos('Re₧ie:', Line);
  44.     if BeginPos > 0 then
  45.     begin
  46.       Delete(Line,1,BeginPos+5);
  47.       BeginPos := Pos('<br>', Line);
  48.       if BeginPos = 0 then BeginPos := Length(Line);
  49.       result := copy(Line, 1, BeginPos);
  50.       HTMLDecode(result);
  51.       HTMLRemoveTags(result);
  52.     end;
  53.   result := Trim(result);
  54. end;
  55.  
  56. function GetActor(Line: string): String;
  57. var BeginPos : Integer;
  58. begin
  59.     result := '';
  60.     BeginPos := Pos('Hrajφ:', Line);
  61.     if BeginPos > 0 then
  62.     begin
  63.       Delete(Line,1,BeginPos + 5);
  64.       BeginPos := Pos('<br>', Line);
  65.       if BeginPos = 0 then BeginPos := Length(Line);
  66.       result := copy(Line, 1, BeginPos);
  67.       HTMLDecode(result);
  68.       HTMLRemoveTags(result);
  69.     end;
  70.   result := Trim(result);
  71. end;
  72.  
  73. function GetTitle(Line: string): String;
  74. var BeginPos : Integer;
  75. begin
  76.     result := '';
  77.     BeginPos := Pos('<img src=''/images/flag_52.gif', Line);
  78.     if BeginPos > 0 then
  79.     begin
  80.       Delete(Line,1,BeginPos-1);
  81.       BeginPos := Pos('</table>', Line);
  82.       if BeginPos = 0 then BeginPos := Length(Line);
  83.       result := copy(Line, 1, BeginPos);
  84.       HTMLDecode(result);
  85.       HTMLRemoveTags(result);
  86.       MovieName := GetField(fieldTranslatedTitle);
  87.       MovieName := MovieName + ' (' + result + ')';
  88.       SetField(fieldTranslatedTitle,MovieName);
  89.       Delete(Line,1,BeginPos-1);
  90.     end
  91.  
  92.     BeginPos := Pos(' ', Line);
  93.     if BeginPos > 0 then
  94.     begin
  95.       Delete(Line,BeginPos, Length(Line));
  96.       result := Line;
  97.       HTMLDecode(result);
  98.       HTMLRemoveTags(result);
  99.     end;
  100.   result := Trim(result);
  101. end;
  102.  
  103. function GetCategory(Line: string): String;
  104. var BeginPos : Integer;
  105. begin
  106.     result := '';
  107.     BeginPos := Pos(' ', Line);
  108.     if BeginPos > 0 then
  109.     begin
  110.       Delete(Line,1,BeginPos + 9);
  111.       BeginPos := Pos('<br>', Line);
  112.       if BeginPos = 0 then BeginPos := Length(Line);
  113.       result := copy(Line, 1, BeginPos-1);
  114.       HTMLDecode(result);
  115.       HTMLRemoveTags(result);
  116.     end;
  117.     result := Trim(result);
  118.     SetField(fieldCategory, result);
  119.     result := '';
  120.     Delete(Line,1,BeginPos-1);
  121.     BeginPos := Pos('<br>', Line);
  122.     if BeginPos > 0 then
  123.     begin
  124.       Delete(Line,1,BeginPos + 3);
  125.       BeginPos := Pos('<p>', Line);
  126.       if BeginPos = 0 then BeginPos := Length(Line);
  127.       result := copy(Line, 1, BeginPos-1);
  128.       HTMLDecode(result);
  129.       HTMLRemoveTags(result);
  130.     end;
  131.     result := Trim(result);
  132.     SetField(fieldCountry, result);
  133. end;
  134.  
  135. procedure AnalyzePage(Address: string);
  136. var
  137.   Page: TStringList;
  138.   LineNr : Integer;
  139.   Line, Value : String;
  140.   BeginPos, EndPos : Integer;
  141.   FilmName, FilmAddr : String;
  142. begin
  143.     Page := TStringList.Create;
  144.     Page.Text := GetPage(Address);
  145.     LineNr := FindLine('databßze</title>', Page, 0);
  146.     if LineNr = -1 then
  147.     begin
  148.         AnalyzeMoviePage(Address);
  149.     end
  150.     else
  151.     begin
  152.      LineNr := FindLine('Nebyly nalezeny ₧ßdnΘ', Page, 0);
  153.       if LineNr = -1 then
  154.       begin
  155.         LineNr := FindLine('<a href="film.', Page, 0);
  156.         if LineNr > -1 then
  157.         begin
  158.           PickTreeClear;
  159.           PickTreeAdd('Filmy: ' + MovieName, '');
  160.           Line := Page.GetString(LineNr);
  161.           repeat
  162.             BeginPos := Pos('<a href="',Line);
  163.             If BeginPos > 0 Then
  164.             begin
  165.               EndPos := Pos('">',Line);
  166.               if EndPos = 0 Then EndPos := Length(Line);
  167.               FilmAddr := Copy(Line, BeginPos+9, EndPos-BeginPos-9);
  168.               HTMLDecode(FilmAddr);
  169.               HTMLRemoveTags(FilmAddr);
  170.               EndPos := Pos('<br>',Line);
  171.               if EndPos = 0 Then EndPos := Length(Line);
  172.               FilmName := Copy(Line, BeginPos, EndPos-BeginPos);
  173.               HTMLDecode(FilmName);
  174.               HTMLRemoveTags(FilmName);
  175.               PickTreeAdd(FilmName, BaseAddress + FilmAddr);
  176.               Delete(Line,1,EndPos+3);
  177.             end;
  178.           until BeginPos <1;
  179.          If  PickTreeExec(Address) Then
  180.            AnalyzeMoviePage(Address);
  181.         end;
  182.       end;
  183.     end;
  184. end;
  185.  
  186. procedure AnalyzeMoviePage(Address: string);
  187. var
  188.   Page: TStringList;
  189.   LineNr : Integer;
  190.   Line, Value : String;
  191.   BeginPos, EndPos : Integer;
  192. begin
  193.     Page := TStringList.Create;
  194.     Page.Text := GetPage(Address);
  195.     LineNr := FindLine('<div class="nazovfilmu">', Page, 0);
  196.     if LineNr > -1 then
  197.     begin
  198.  
  199.       Line := Page.GetString(LineNr+1);
  200.       HTMLDecode(Line);
  201.       HTMLRemoveTags(Line);
  202.       Value := Trim(Line);
  203.       SetField(fieldTranslatedTitle, Value);
  204.  
  205.       Line := Page.GetString(LineNr+2);
  206.       Value := GetDirector(Line);
  207.       SetField(fieldDirector, Value);
  208.       Value := GetActor(Line);
  209.       SetField(fieldActors, Value);
  210.       Value := GetTitle(Line);
  211.       SetField(fieldOriginalTitle, Value);
  212.       Value := GetCategory(Line);
  213.     end;
  214.     // picture
  215.     LineNr := FindLine('style="padding-left: 10px"', Page, 0);
  216.     if LineNr > -1 then
  217.     begin
  218.       Line := Page.GetString(LineNr);
  219.       BeginPos := pos('<img src="', Line) + 10;
  220.       if BeginPos > 10 then
  221.         begin
  222.           EndPos := pos('" width="', Line);
  223.           Value := copy(Line, BeginPos, EndPos - BeginPos);
  224.           Value := BaseAddress + Value;
  225.           GetPicture(Value, False);
  226.         end;
  227.     end;
  228.     // Info
  229.     LineNr := FindLine('id="plot_full"', Page, 0);
  230.     if LineNr > -1 then
  231.     begin
  232.       Value := Page.GetString(LineNr+1);
  233.       HTMLDecode(Value);
  234.       HTMLRemoveTags(Value);
  235.       SetField(fieldDescription, Trim(Value));
  236.     end;
  237.    // URL
  238.    SetField(fieldURL, Address);
  239.   DisplayResults;
  240. end;
  241.  
  242. begin
  243.   if CheckVersion(3,4,0) then
  244.   begin
  245.     MovieName := GetField(fieldOriginalTitle);
  246.     if MovieName = '' then
  247.       MovieName := GetField(fieldTranslatedTitle);
  248.     if Input('Import movie from www.csfd.cz', 'Enter the title of the movie:', MovieName) then
  249.     begin
  250.          AnalyzePage(BaseAddress + 'index.php?action=hledat&hledej='+UrlEncode(MovieName));
  251.     end;
  252.   end else
  253.     ShowMessage('This script requires a newer version of Ant Movie Catalog (at least the version 3.4.0)');
  254. end.
  255.